<?php
/**
 *
 * @category   DDB
 * @package    Ddb_View
 * @subpackage Helper
 * @copyright  Copyright (c) 2005-2009 DDB
 * @version    $Id: FormHiddenDisplay.php 16541 2009-10-12 17:02:30Z tbrouard $
 */
/**
 * Abstract class for extension
 */
require_once 'Zend/View/Helper/FormElement.php';

/**
 * Helper to generate a "hidden" element
 *
 * @category DDB
 * @package Ddb_View
 * @subpackage Helper
 */
class Jnd_View_Helper_FormAdvancedTextarea extends Zend_View_Helper_FormTextarea
{

    /**
     * Generates a 'hidden' element.
     *
     * @access public
     *        
     * @param string|array $name
     *            If a string, the element name. If an
     *            array, all other parameters are ignored, and the array
     *            elements
     *            are extracted in place of added parameters.
     * @param mixed $value
     *            The element value.
     * @param array $attribs
     *            Attributes for the element tag.
     * @return string The element XHTML. div tag + input hidden tag
     */
    public function formAdvancedTextarea ($name, $value = null, 
            array $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);
        $defaultAttribs = array(
                "toolbar" => '',
                "height" => 300,
                "width" => 700
        );
        extract($info); // name, value, attribs, options, listsep, disable
        if (isset($id)) {
            if (isset($attribs) && is_array($attribs)) {
                $attribs['id'] = $id;
            } else {
                $attribs = array(
                        'id' => $id
                );
            }
        } else {
            $attribs['id'] = $name;
        }
        $attribs['name'] = $name;
        $attribs = array_merge($defaultAttribs, $attribs); 
        $toolbar = (isset($attribs['toolbar']) ? $attribs['toolbar'] : '');
        $jquery = Jnd_App::getConfig('jquery');
        $view = Jnd_App::getResource("view");
        $view->jQuery()
            ->addJavascriptFile(
                $jquery['path']['min'] . 'plugins/ckeditor/ckeditor.js')
            ->addJavascriptFile(
                $jquery['path']['min'] . 'plugins/ckeditor/adapters/jquery.js');

        
        $view->jQuery()->addonLoad(
                "$('#" . $attribs['id'] .
                         "').ckeditor({path: 'plugins/ckeditor/', height:" .
                         $attribs['height'] . ", width:" . $attribs['width'] .
                         " " . ($toolbar != "" ? ",toolbar: '$toolbar'" : "") .
                         " });"); 
        $helper = new Zend_View_Helper_FormTextarea();
        $helper->setView($view); 
        return $helper->formTextarea($attribs['id'], $value, $attribs); 
    }
}
